<template>
  <i>
    {{ showTime }}
  </i>
</template>

<script>
export default {
  data() {
    return {
      time: 900,
      showTime: "",
    };
  },
  props: {
    itemPass: {
      type: Number,
      default: 0,
    },
  },
  created() {
    this.time -= this.itemPass;

    let formatTimeM = (this.time / 60).toFixed(0);
    let formatTimeS = this.time % 60;
    if (formatTimeM < 0) {
      return;
    }

    // 倒计时效果
    const timer = setInterval(() => {
      if (Number(formatTimeS)) {
        formatTimeS--;
        formatTimeS = formatTimeS >= 10 ? formatTimeS : "0" + formatTimeS;

        if (!Number(formatTimeM) && !Number(formatTimeS)) {
          clearInterval(timer);
          this.$toast.handleTipsText("支付超时");
        }
      } else {
        formatTimeM--;
        formatTimeM = formatTimeM >= 10 ? formatTimeM : "0" + formatTimeM;
        formatTimeS = 59;
      }
      this.showTime = `(还剩${formatTimeM}分${formatTimeS}秒)`;
    }, 1000);
  },
};
</script>
<style scoped>
</style>